package cu.ds.logicalsync.fytasrealm.model;

import java.util.Random;

public class Map {
	
	private PositionMap mapRoom[][] = new PositionMap[400][300]; //row,col,occupy?,color,worldname
	//private PositionMap myMapStatus;	//row,col,occupy?
	
	public PositionMap[][] getMapRoom() {
		return this.mapRoom;
	}
	@SuppressWarnings("null")
	public void setMapRoom(int row,int col,String action) { // in case : go to specific world in map
		PositionMap pm = null;
		pm.setRowPosition(row);
		pm.setColPosition(col);
		//set color to tell red or green (not concern to blue yet)
		if (action == "goto") {
			pm.setPositionOccupy(true);
			pm.setPositionColor("Others",pm.isOccupy());
		}
		else if (action == "leave") {
			pm.setPositionOccupy(false);
			pm.setPositionColor("Others",pm.isOccupy());
		}
		this.mapRoom[row][col] = pm;
	}
	public void setMapRoom(String worldName) {
		randomPosition(worldName);
	}
	@SuppressWarnings("null")
	public void randomPosition(String worldName) {
		boolean randomSuccess = false;
		PositionMap pm = null;
		while (!randomSuccess) {
			Random generator = new Random();
			int randomRow = generator.nextInt(400);
			int randomCol = generator.nextInt(300);
			pm.setRowPosition(randomRow);
			pm.setColPosition(randomCol);
			pm.setPositionOccupy(true);
			pm.setWorldNameInMap(worldName);
			pm.setPositionColor("Others", pm.isOccupy());
			this.mapRoom[randomRow][randomCol] = pm;
			randomSuccess = !pm.isOccupy();
		}
	}
	
	
	
	public Map() {
		//this.mapPosition[][] = new PositionMap[400][300];
		//map size = 400*300
		//actual: get current state from Toey
		int i,j;
		for (i=0; i<400; i++) {
			for (j=0; j<300; j++) {
				PositionMap pm = new PositionMap(i,j);
				pm.setPositionOccupy(false);
				this.mapRoom[i][j] = pm;
			}
		}
	}
	
	/**** Tay Add 20090918***/
	private MapState state = MapState.Empty;

	/**
	 * @return the state
	 */
	public MapState getState() {
		return state;
	}
	/**
	 * @param state the state to set
	 */
	public void setState(MapState state) {
		this.state = state;
	}
	
}
